<template>
	<view class="header" :style="[customStyle()]">

		<view class="header-wrap">
			<view class="left-secton" v-if="isHome">
				<view class="back" @click="goBack">

					<image mode="heightFix" src="/static/goback.png" />

				</view>
				<view class="home" @click="goHome">
					<image mode="heightFix" src="/static/gohome.png" />
				</view>
			</view>
			<view class="img" v-if="!isWhite">
				<image src="/static/logo.png" />
			</view>
			<view class="img" v-else style="background-color: #fff;"></view>
			<view class="title" :style="{color: !isWhite ? '#fff' : '#333'}">
				{{ title }}

			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	export default {
		props: {
			title: {
				type: String,
				isHome: false,
				isWhite: false,
			},
			isHome: false,
			isWhite: false,
			bgColor: {
				type: String,
				default: "#fff",
			},
			groupId: {
				type: String,
				default: "",
			},
			groupMemberCount: {
				type: String,
				default: "",
			},
			orderType: {
				type: Number,
				default: 0,
			},
		},
		data() {
			return {
				pages: getCurrentPages(),
				platform: uni.getSystemInfoSync().platform,
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,

			};
		},
		// computed: {
		// 	...mapState(["statusBarHeight"]),
		// },
		methods: {
			// ...mapMutations(["saveTabIndex"]),
			async goBack() {
				let param = {
					groupId: this.groupId,
				};
				this.pages.length == 1 ?
					uni.switchTab({
						url: "/pages/index/index",
					}) :
					uni.navigateBack({
						delta: 1,
						success: function() {

							if (param.groupId !== "") {
								const pages = getCurrentPages();
								const prevPage = pages[pages.length - 1];
								prevPage.onLoad(param);
							}
						},
					});
			},

			goHome() {

				uni.switchTab({
					url: "/pages/index/index",
				});
				// this.saveTabIndex(0);
			},
			customStyle() {
				return {
					"padding-top": `${this.statusBarHeight}px`,

					background: this.bgColor,
				};
			},
		},
	};
</script>

<style lang="scss" scoped>
	.header {
		position: sticky;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 90;
		box-sizing: border-box;
		display: flex;
		justify-content: center;

		.img {


			image {
				width: 255rpx;
				height: 50rpx;
				// background-color: #007FC3;
				display: block;
				margin: 0 auto;
			}
		}

		.header-wrap {
			width: 100%;
			height: 44px;
			position: relative;
			line-height: 44px;
			display: flex;
			align-items: center;
			position: relative;
			justify-content: center;

			.left-secton {
				display: flex;
				align-items: center;
				position: absolute;
				left: 32rpx;

				.back {
					width: 40rpx;
					height: 40rpx;

					image {
						width: 100%;
						height: 100%;
						display: block;
					}
				}

				.home {
					width: 40rpx;
					height: 40rpx;
					margin-left: 28rpx;

					image {
						width: 100%;
						height: 100%;
						display: block;
					}
				}

			}

			.title {
				text-align: center;
				font-weight: 500;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFangSC-Medium;
				font-weight: 500;
				font-size: 36rpx;
				color: #1A1A1A;
				width: 340rpx;
				white-space: nowrap;
				/* 防止文本换行 */
				overflow: hidden;
				/* 隐藏溢出部分 */
				text-overflow: ellipsis;

				.title-text {
					max-width: 40%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					display: flex;
					align-items: center;

					image {
						width: 56rpx;
						height: 40rpx;
						margin-right: 10rpx;
					}

					.title-text-in {
						color: #fa5151;
					}

					.title-text-out {
						color: #00b578;
					}
				}

			}
		}
	}

	.home {
		display: flex;
		align-items: center;
		height: 100%;
		padding: 0 10rpx;
	}
</style>